#include <iostream>
using namespace std;
int min=999999999;
	int a[5][4]={
	{0,0,1,0},
	{0,0,0,0},
	{0,0,1,0},
	{0,1,0,0},
	{0,0,0,1}
	};
 int book[20][20];
void dfs(int x,int y,int step){
	if(x==3&&y==2){if(step<::min) ::min=step;
	return;
	}
	int next[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
	int nx,ny,k;
	for(k=0;k<=3;k++){
		nx=x+next[k][0];
		ny=y+next[k][1];
		if(nx<0||nx>4||ny<0||ny>3) continue;
		if(book[nx][ny]==0 && a[nx][ny]==0){
			book[nx][ny]=1;
			dfs(nx,ny,step+1);
			book[nx][ny]=0;
		}
	}
	return;
}
int main() {
	book[0][0]=1;
	dfs(0,0,0);
	cout<<::min;
    return 0;
}




